import { defineComponent, computed } from "vue";
import defaultProps from "../props.mjs";
const name = "ep-amount";
const _sfc_main = defineComponent({
  name,
  props: defaultProps,
  emits: ["update:modelValue"],
  setup(props, { emit }) {
    const isDetail = computed(() => props.options.permission > 0);
    const fieldModel = computed({
      get() {
        if (isDetail.value && !props.modelValue) {
          return "--";
        }
        return props.modelValue;
      },
      set(val) {
        emit("update:modelValue", val);
      }
    });
    const handleBlurEvent = (value) => {
      const limitMin = props.options.min || 0;
      const limitMax = props.options.max || 9;
      if (value > limitMax) {
        emit("update:modelValue", limitMax);
      }
      if (value < limitMin) {
        emit("update:modelValue", limitMin);
      }
      if (props.options.omitEndZero && String(value).indexOf(".") !== -1) {
        const filtered = String(value).replace(/\.?0*$/, "");
        if (filtered !== String(value)) {
          emit("update:modelValue", filtered);
        }
      }
    };
    const handleInput = (value) => {
      let filtered = value.replace(/[^\d.]/g, "").replace(/^0+(\d)/, "$1").replace(/(\..*)\./g, "$1");
      if (props.options.decimalPlaces === 2) {
        filtered = filtered.replace(/(\.\d{2})\d+/g, "$1");
      } else {
        filtered = filtered.replace(/(\.\d)\d+/g, "$1");
      }
      if (filtered !== value) {
        emit("update:modelValue", filtered);
      }
    };
    return {
      fieldModel,
      isDetail,
      handleInput,
      handleBlurEvent
    };
  }
});
export {
  _sfc_main as default
};
